import { IMyMusic } from 'apis/types/business'
import { getMusicUrl } from 'utils/business'

import { MODE, setPlayHistory, playMode as playModeLocalStorage } from 'utils/play'
export interface IState {
  musicId: number
  musicUrl: string
  music?: IMyMusic
  playMode: MODE
  showLyric: boolean
}
const store = {
  state: {
    musicId: 0,
    musicUrl: '',
    playMode: playModeLocalStorage.getItem(),
    showLyric: false,
  },
  mutations: {
    play(state: IState, params: any) {
      if (!params?.keepOrder) {
        setPlayHistory(params?.music)
      }
      state.musicId = params?.musicId
      state.musicUrl = getMusicUrl(params?.musicId)
      state.music = params?.music
    },
    setPlayMode(state: IState, params: any) {
      playModeLocalStorage.setItem(params?.playMode)
      state.playMode = params?.playMode || MODE.PLAY_IN_ORDER
    },
  },
}

export default store
